import { createRouter, createWebHistory } from 'vue-router'
import deliveryRoutes from './delivery'

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/forgot',
    name: 'forgot',
    component: () => import('../views/ForgotPassword.vue'),
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('../views/Register.vue'),
  },
  {
    path: '/user',
    component: () => import('../layouts/UserLayout.vue'),
    children: [
      //   ------------------------
      {
        path: '/user/Index',
        name: 'AiUser',
        component: () => import('../views/user/Index.vue'),
      },
      //   -------------------------
      {
        path: '',
        redirect: '/user/home'
      },
      {
        path: 'home',
        name: 'UserHome',
        component: () => import('../views/user/Home.vue')
      },
      {
        path: 'orders',
        name: 'UserOrders',
        component: () => import('../views/user/Orders.vue')
      },
      {
        path: 'address',
        name: 'UserAddress',
        component: () => import('../views/user/Address.vue')
      },
      {
        path: 'profile',
        name: 'UserProfile',
        component: () => import('../views/user/Profile.vue')
      },
      {
        path: 'ditu',
        name: 'UserDiTu',
        component: () => import('../views/user/ditu.vue')
      },
      // {
      //   path: 'index',
      //   name: 'UserIndex',
      //   component: () => import('../views/user/Index.vue')
      // }
    ]
  },
  // 直接展开 deliveryRoutes
  ...deliveryRoutes,
  {
    path: '/admin',
    component: () => import('../layouts/AdminLayout.vue'),
    children: [
      {
        path: '',
        redirect: '/admin/dashboard'
      },
      {
        path: 'dashboard',
        name: 'AdminDashboard',
        component: () => import('../views/admin/Dashboard.vue')
      },
      {
        path: 'users',
        name: 'AdminUsers',
        component: () => import('../views/admin/Users.vue')
      },
      {
        path: 'deliverymen',
        name: 'AdminDeliverymen',
        component: () => import('../views/admin/Deliverymen.vue')
      },
      {
        path: 'orders',
        name: 'AdminOrders',
        component: () => import('../views/admin/Orders.vue')
      },
      // {
      //   path: 'setting',
      //   name: 'AdminSetting',
      //   component: () => import('../views/admin/Setting.vue')
      // },
      // 仓库管理路由组
      {
        path: 'warehouse',
        name: 'AdminWarehouse',
        component: () => import('../views/admin/warehouse/WarehouseIndex.vue'), // 仓库管理父组件
        redirect: '/admin/warehouse/inventory',
        children: [
          {
            path: 'inventory',
            name: 'AdminWarehouseInventory',
            component: () => import('../views/admin/warehouse/Inventory.vue'),
            meta: { title: '库存管理' }
          }
        ]
      },
      // 货物跟踪路由组
      {
        path: 'cargo',
        name: 'AdminCargo',
        component: () => import('../views/admin/cargo/CargoIndex.vue'),
        redirect: '/admin/cargo/tracking',
        children: [
          {
            path: 'tracking',
            name: 'AdminCargoTracking',
            component: () => import('../views/admin/cargo/Tracking.vue'),
            meta: { title: '实时定位' }
          },
          {
            path: 'alerts',
            name: 'AdminCargoAlerts',
            component: () => import('../views/admin/cargo/Alerts.vue'),
            meta: { title: '异常预警' }
          }
        ]
      },

    ]
  },
 

  {
    path: '/mobile/confirm',
    name: 'MobileConfirm',
    component: () => import('@/views/mobile/MobileConfirm.vue')
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

export default router
